﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConceptionLogiciel_Devoir1
{
    class CatalogueVehicule
    {
        private static CatalogueVehicule _instance;
        static readonly object instanceLock = new object();

        private Dictionary<String, Vehicule> mapVehicule;

        // Constructor
        // -------------------------------------------------------------------------------
        private CatalogueVehicule()
        {
            this.mapVehicule = new Dictionary<String, Vehicule>();
            // params Vehicule: noSerie, immatriculation, marque, modele, annee
            mapVehicule.Add("777e44e", new Vehicule("777e44e", "EDQ 798", "Nissan", "350z", 2013, 21));
            mapVehicule.Add("819q789", new Vehicule("819q789", "QSZ 999", "Nissan", "GTR", 2013, 22));
            mapVehicule.Add("258wqqq", new Vehicule("258wqqq", "SCB 314", "Subaru", "STI", 2009, 20));
            mapVehicule.Add("8254er7", new Vehicule("8254er7", "CBB 351", "Subaru", "BRZ", 2012, 23));
        }

        // Retourne l'intance du catalogue de véhicule (pattern singleton)
        // -------------------------------------------------------------------------------
        public static CatalogueVehicule getInstance()
        {
            lock (instanceLock)
            {
                if (_instance == null)
                    _instance = new CatalogueVehicule();

                return _instance;
            }
        }

        // Ajoute le véhicule
        // -------------------------------------------------------------------------------
        public void addVehicule(String _noSerie, Vehicule _vehicule)
        {
            mapVehicule.Add(_noSerie, new Vehicule(_vehicule));
        }

        // Retourne le véhicule
        // -------------------------------------------------------------------------------
        public Vehicule getVehicule(String _noVehicule)
        {
            return (Vehicule) mapVehicule[_noVehicule];
        }

        // Retourne la map en entier
        // -------------------------------------------------------------------------------
        public Dictionary<String, Vehicule> getCatalogueVehicule()
        {
            return mapVehicule;
        }

    }  // End class Catalogue
}  // End namespace devoir3_conception_location
